setfenv(1, require'winapi.oo')
require'winapi.oo.control'
require'winapi.edit'

EditBox = class(Control)

function EditBox:__init(info)
	self.window = CreateEdit(update({}, info, {
							parent = info.parent and info.parent.window
						}))
	self.parent = info.parent
	App.router:add_handler('Control', self.window,
		function(...) return self:__handle_notifications(...) end)
end

function EditBox:__handle_notifications(_, WM, EN, wParam, lParam)
	local handler = self['on_'..(EDIT_NOTIFICATION_NAMES[EN]:lower())]
	if handler then handler(self, wParam, lParam) end
end

function EditBox:get_caption() local s = GetWindowText(self.window); return ffi.string(s, ffi.sizeof(s)-2) end
function EditBox:set_caption(v) self.window.caption = v end

if not ... then
require'winapi.oo.showcase'
local window = ShowcaseWindow{w=300,h=200}
local e1 = EditBox{parent = window}
function e1:on_change() print('changed', self.caption) end
local e2 = EditBox{parent = window, y = 40}
App:run()
end

